import { ref } from 'vue'
import { TimeoutTipForm } from './types'
import { workTimeoutRemind } from '@/api/order'

const useTimeoutTipForm = () => {
  const form = ref<TimeoutTipForm>({
    remindEmpIds: [],
    remindEmpType: [],
    type: 1,
    conditionType: null,
  })

  const submitLoading = ref(false)

  const submit = async (orderIds: Array<string>) => {
    submitLoading.value = true
    const res = await workTimeoutRemind({ ...form.value, workIds: orderIds })
    submitLoading.value = false
    return res.data as { code: number; data: object; message: string; success: boolean }
  }

  const reset = () => {
    form.value.remindEmpIds = []
    form.value.remindEmpType = []
    form.value.type = 1
    form.value.conditionType = null
  }

  return {
    form,
    submitLoading,
    reset,
    submit,
  }
}

export default useTimeoutTipForm
